#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <error.h>
#include <unistd.h>
#include <string.h>

using namespace std;
#define BUFFERSIZE 16

int main()
{
    int ret = truncate("test1.txt", 100);   //改变文件长度
    if(ret == -1)
    {
        perror("truncate error:");
        exit(-1);
    }

    struct stat buf;
    stat("test1.txt", &buf);
    cout << "size:" << buf.st_size << endl;

    return 0;
}